package com.danh.game;

import android.app.Activity;
import android.opengl.Visibility;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Interpolator;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.view.animation.TranslateAnimation;

public class DemoGameActivity extends Activity {
	// TODO Image view
	View imgView_Start;
	View imgView_Extra;
	View imgView_Options;

	// TODO Animation
	Animation mAnimation_Start;
	private View imgView_Menu;
	private View imgView_Menu_2;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.mainmenu);

		// TODO init image view
		imgView_Start = findViewById(R.id.imgView_Start);
		imgView_Extra = findViewById(R.id.imgView_Extra);
		imgView_Options = findViewById(R.id.imgView_Options);
		imgView_Menu = findViewById(R.id.imgMenu);
		imgView_Menu_2 = findViewById(R.id.imgMenu_2);

		// TODO load animation for image view
		mAnimation_Start = AnimationUtils.loadAnimation(this, R.anim.slide);
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();

		if (imgView_Start != null) {
			AlphaAnimation mAnimation = new AlphaAnimation(0f, 1f);
			mAnimation.setDuration(1000);
			mAnimation.setStartOffset(500L);			
			imgView_Start.startAnimation(mAnimation);
		}
		if (imgView_Extra != null) {
//			Animation anim = mAnimation_Start;
//			anim.setStartOffset(500L);
			
			AlphaAnimation mAnimation = new AlphaAnimation(0f, 1f);
			mAnimation.setDuration(1000);
			mAnimation.setStartOffset(1500L);			
			imgView_Extra.startAnimation(mAnimation);
		}
		if (imgView_Options != null) {
//			Animation anim = mAnimation_Start;
//			anim.setStartOffset(1000L);
			
			AlphaAnimation mAnimation = new AlphaAnimation(0f, 1f);
			mAnimation.setDuration(1000);
			mAnimation.setStartOffset(2500L);			
			
//			TranslateAnimation mTranslate = new TranslateAnimation(0, 500, 0,-300);
//			mTranslate.setFillAfter(true);
//			mTranslate.setDuration(4000);
//			mTranslate.setStartOffset(2500L);
//			
			mAnimation.setAnimationListener(new AnimationListener() {
				
				@Override
				public void onAnimationStart(Animation animation) {
					// TODO Auto-generated method stub
					
				}
				
				@Override
				public void onAnimationRepeat(Animation animation) {
					// TODO Auto-generated method stub
					
				}
				
				@Override
				public void onAnimationEnd(Animation animation) {
					// TODO Auto-generated method stub
					TranslateAnimation mTranslate = new TranslateAnimation(100,0, 0,0);
					mTranslate.setFillBefore(true);
					mTranslate.setDuration(500);
					mTranslate.setRepeatCount(5);
//					mTranslate.setStartOffset(2500L);
					
					mTranslate.setAnimationListener(new AnimationListener() {
						
						@Override
						public void onAnimationStart(Animation animation) {
							// TODO Auto-generated method stub
							
						}
						
						@Override
						public void onAnimationRepeat(Animation animation) {
							// TODO Auto-generated method stub
							
						}
						
						@Override
						public void onAnimationEnd(Animation animation) {
							// TODO Auto-generated method stub
							TranslateAnimation mTranslate1 = new TranslateAnimation(100,0, 0,0);
							mTranslate1.setFillAfter(true);
							mTranslate1.setDuration(500);														
							imgView_Menu_2.setVisibility(View.VISIBLE);
							imgView_Menu_2.setAnimation(mTranslate1);
						}
					});
					
					imgView_Menu.setVisibility(View.VISIBLE);
					imgView_Menu.setAnimation(mTranslate);
				}
			});
			imgView_Options.startAnimation(mAnimation);
			
		}

	}
}